package com.jtpay.payresulthelper.app;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import com.jtpay.payresulthelper.util.manager.AppManager;
import com.jtpay.payresulthelper.util.manager.PageManagement;

public class HelperApplication extends Application {
    protected static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        AppManager.init(mContext);
        registerActivityListener();
    }

    public static Context getContext() {
        return mContext;
    }

    private void registerActivityListener() {
        //api 4.0开始才可使用
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                /*
                 *  监听到 Activity创建事件 将该 Activity 加入list
                 */
                PageManagement.getInstance().pushAC(activity);
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                PageManagement.getInstance().removeAC(activity);
            }
        });
    }
}
